package com.erp.gather.controller;

import com.erp.gather.domain.bo.ErpCollectProductCategoryKeyBo;
import com.erp.gather.domain.vo.ErpCollectProductCategoryKeyVo;
import com.erp.gather.service.IErpCollectProductCategoryKeyService;
import com.ruoyi.common.core.annotation.RepeatSubmit;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.validate.AddGroup;
import com.ruoyi.common.core.validate.EditGroup;
import com.ruoyi.common.core.web.oldController.BaseController;
import com.ruoyi.common.core.web.oldPage.TableDataInfo;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.util.Arrays;
import java.util.List;

/**
 * 泪目key
 *
 * @author erp
 * @date 2023-04-20
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/gather/collectProductCategoryKey")
public class ErpCollectProductCategoryKeyController extends BaseController {

    private final IErpCollectProductCategoryKeyService iErpCollectProductCategoryKeyService;

    /**
     * 查询泪目key列表
     */
    @GetMapping("/list")
    public TableDataInfo<ErpCollectProductCategoryKeyVo> list(ErpCollectProductCategoryKeyBo bo, PageQuery pageQuery) {
        return iErpCollectProductCategoryKeyService.queryPageList(bo, pageQuery);
    }

    /**
     * 获取泪目key详细信息
     *
     * @param id 主键
     */
    @GetMapping("/{id}")
    public R<ErpCollectProductCategoryKeyVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long id) {
        return R.ok(iErpCollectProductCategoryKeyService.queryById(id));
    }

    /**
     * 新增泪目key
     */
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody ErpCollectProductCategoryKeyBo bo) {
        return toAjax(iErpCollectProductCategoryKeyService.insertByBo(bo));
    }

    /**
     * 修改泪目key
     */
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody ErpCollectProductCategoryKeyBo bo) {
        return toAjax(iErpCollectProductCategoryKeyService.updateByBo(bo));
    }

    /**
     * 删除泪目key
     *
     * @param ids 主键串
     */
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] ids) {
        return toAjax(iErpCollectProductCategoryKeyService.deleteWithValidByIds(Arrays.asList(ids), true));
    }
}
